package cate.game.admin.menu.hero;

import cate.common.table.item.hero.row.HeroBaseRow;
import cate.game.GameBody;
import cate.game.admin.menu.MenuSetup;
import cate.game.client.msg.MergeMsgSender;
import cate.game.fight.test.HeroDevUtil;
import cate.game.role.bag.hero.Hero;
import cate.game.role.bag.hero.msg.HeroInitResp;
import cate.game.train.hero.msg.HeroBaseUpdateResp;

import java.util.ArrayList;

public class HeroMenu extends MenuSetup {

    public HeroMenu(GameBody game) {
        super("英雄");
        reg(game, "升到顶级", 0, "", (role, params) -> {
            role.getBag().hero.getList().forEach(h -> {
                HeroBaseRow tpl = h.getTpl(game);
                if (h.level < tpl.levelMax) {
                    h.level = tpl.levelMax;
                    h.grade = tpl.gradeMax;
                    h.markPowerExpire();
                    HeroBaseUpdateResp.send(role, h);
                }
            });
            role.getRes().worldTree.heroShare.onHeroLvlChange(true);
            game.notice.message(role, "成功!");
        });

        reg(game, "满灵器", 0, "", (role, params) -> {
            role.getBag().hero.getList().forEach(h -> {
                HeroBaseRow tpl = h.getTpl(game);
                HeroDevUtil.handleTopFairy(role, tpl, h);
            });
            role.sendNow(new HeroInitResp(role));
            game.notice.message(role, "成功!");
        });

        reg(game, "尽量满战力", 0, "【等级】【阶数】【装备】【宝石】【灵器】【觉醒灵器】" +
                        "【徽章】【天赋】【星格】【好感】【手办】【家具】【厨具】",
                (role, params) -> {
                    MergeMsgSender sender = new MergeMsgSender();
                    role.getBag().spice.getList().clear();
                    for (Hero hero : new ArrayList<>(role.getBag().hero.getList())) {
                        HeroBaseRow heroTpl = hero.getTpl(game);
                        HeroDevUtil.handleTopLevel(role, heroTpl, hero);
                        HeroDevUtil.handleTopEquip(role, hero);
                        HeroDevUtil.handleTopFairy(role, heroTpl, hero);
                        HeroDevUtil.handleTopAwakenFairy(role, heroTpl, hero);
                        HeroDevUtil.handleTopRune(role, heroTpl, hero);
                        HeroDevUtil.handleTopTalent(heroTpl, hero);
                        HeroDevUtil.handleTopSpice(role, heroTpl, hero, sender);
                        HeroDevUtil.handleFavor(role, heroTpl, hero);
                        HeroDevUtil.handleFurniture(role, heroTpl, hero);
                        HeroDevUtil.handleYoke(role, heroTpl, hero, sender);
                        HeroDevUtil.handleKitchenware(role, heroTpl, hero);
//                        if (heroTpl.job != GDHero.Job.J4) {
//                            hero.inscriptionPageOn.page = 1;
//                        } else {
//                            hero.inscriptionPageOn.page = 2;
//                        }
                        hero.markPowerExpire();
                    }
                    sender.send(role, true);
                    role.sendNow(new HeroInitResp(role));
                    role.getRes().worldTree.heroShare.onHeroLvlChange(true);
                    game.notice.message(role, "成功!");
                });
    }


}
